package m202405.d16;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/16 10:51
 */
public class Q121 {
    public int maxProfit(int[] prices) {
        int minPrice = Integer.MAX_VALUE;
        int res = 0;
        for (int price : prices) {
            if (price < minPrice) {
                minPrice = price;
            } else {
                res = Math.max(price - minPrice, res);
            }
        }
        return res;
    }
}
